// pages/roomRank/roomRank.js
let md5 = require("../../utils/md5.js")
let axios = require("../../utils/util.js")
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    roomId: "74",
    type: 1, //0财富1魅力
    dateType: 1, //1日榜2周榜
    rankList1: "",
    rankList2: "",
    img_level: "https://xunyinjiaoyou.oss-cn-qingdao.aliyuncs.com/static/level/",
    img_charm: "https://xunyinjiaoyou.oss-cn-qingdao.aliyuncs.com/static/charmlevel/",
  },
  return () {
    wx.navigateBack({
      delta: 1,
    })
  },
  typeChange1() {
    this.setData({
      type: 1
    })
    this.getRank()
  },
  typeChange0() {
    this.setData({
      type: 0
    })
    this.getRank()
  },
  dateChange(data) {
    console.log(data);
    this.setData({
      dateType: data.currentTarget.dataset.datechange
    })
    this.getRank()
  },

  topersonpage(data) {
    // console.log(data.currentTarget.dataset.id)
    wx.navigateTo({
      url: '/pages/personpage/personpage?memberId=' + data.currentTarget.dataset.id,
    })
  },
  tome(data) {
    wx.navigateTo({
      url: '/pages/me/me?memberId=' + data.currentTarget.dataset.memberid,
    })
  },
  getRank() {
    let timestamp = (Date.parse(new Date()) / 1000).toString();
    let _token =
      "userId=" +
      app.globalData.user_id +
      "&type=" +
      this.data.type +
      "&token=" +
      app.globalData.userToken +
      "&time=" +
      timestamp +
      "&roomId=" +
      this.data.roomId +
      "&dateType=" +
      this.data.dateType +
      "&wPQvCAOU$lbIyg9o2wVg0Dt1k^zy&SaX";
    let params = {
      userId: app.globalData.user_id,
      token: app.globalData.userToken,
      type: this.data.type,
      roomId: this.data.roomId,
      dateType: this.data.dateType,
      time: timestamp,
      sign: md5.hexMD5(_token),
    };
    axios.axios({
      url: "/chat/rank_in_room",
      data: params
    }).then((res) => {
      console.log(res.data.result)
      this.setData({
        rankList1: res.data.result.splice(0, 3),
        rankList2: res.data.result
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      roomId: options.roomId
    })
    this.getRank()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})